package com.xbdun.dao.bmp.mapper;

import java.util.List;
import java.util.Set;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.xbdun.dao.bmp.provider.PowerUserMenuMapperProvider;

/**
* @ClassName: PowerUserMenuMapper
* @Description	员工权限
* @author zhanggt 360730440@qq.com
* @date 2017年4月26日 下午3:44:28
 */
@Mapper
public interface PowerUserMenuMapper {
		/**
	* @Title: delOrgUserByMenu
	* @Description: 根据当前机构+部门角色+菜单进行删除
	* @param orgCode			当前机构
	* @param orleDepartId		部门关联角色ID
	* @param menus				删除的菜单列表
	* @return int    返回类型
	 */
	@DeleteProvider(type=PowerUserMenuMapperProvider.class,method="delOrgUserByMenuSql")
	public int delOrgByMenu(@Param("orgCode")Long orgCode,@Param("orleDepartId")Long orleDepartId,@Param("menus")List<Long> menus);
	
	/**
	* @Title: addOrgUserMenu
	* @Description	新增部门角色关联用户，部门不能为空
	* @param userCode		用户编号
	* @param orgCode		机构用户
	* @param roleDptIds		部门角色关联菜单ID
	* @return int    返回类型
	*/
	@InsertProvider(type=PowerUserMenuMapperProvider.class,method="addOrgUserMenuSql")
	public int addOrgUserMenu(@Param("userCode")long userCode,@Param("orgCode")long orgCode,@Param("departCode")long departCode,@Param("roleDptIds")Set<Long> roleDptIds);
	
	/**
	* @Title: delOrgUserMenu
	* @Description: 删除机构用户下关联的菜单
	* @param userCode	用户Code
	* @param orgCode	机构Code
	* @param roleDptIds	关联角色部门ID
	* @return int    返回类型
	 */
	@DeleteProvider(type=PowerUserMenuMapperProvider.class,method="delOrgUserMenuSql")
	public int delOrgUserMenu(@Param("userCode")long userCode,@Param("orgCode")long orgCode,@Param("roleDptIds")Set<Long> roleDptIds);
	
	/**
	* @Title: addOrguserSpecil
	* @Description 新加入特殊权限
	* @param userCode		用户编号
	* @param orgCode		机构用户
	* @param menus			菜单
	* @param type			特殊菜单类型
	* @return int    返回类型
	*/
	@InsertProvider(type=PowerUserMenuMapperProvider.class,method="addOrguserSpecilSql")
	public int addOrgUserSpecil(@Param("userCode")long userCode,@Param("orgCode")long orgCode,@Param("menus")Set<Long> menus,@Param("type")int type);
	
	/**
	* @Title: delOrgUserSpecil
	* @Description: 删除特殊权限菜单
	* @param userCode	用户编号
	* @param orgCode	用户所在机构
	* @param menus		删除的菜单项
	* @return int    返回类型
	 */
	@DeleteProvider(type=PowerUserMenuMapperProvider.class,method="delOrgUserSpecilSql")
	public int delOrgUserSpecil(@Param("userCode")long userCode,@Param("orgCode")long orgCode,@Param("menus")Set<Long> menus);
	/**
	* @Title: querySetSpecialMenu
	* @Description 查询已经设置的机构用户权限菜单
	* @return    设定文件
	* @return List<String>    返回类型
	*/
	@Select("SELECT CAST(code AS CHAR) FROM xbdun_power_user_spec WHERE userCode=#{userCode} AND orgCode=#{orgCode} GROUP BY code")
	public List<String> querySetSpecialMenu(@Param("userCode")long userCode,@Param("orgCode")long orgCode);

	/**
	* @Title: queryOrgUserPower
	* @Description	查询机构下部门角色权限
	* @param userCode	用户编号
	* @param orgCode	机构编号
	* @return List<String>    返回类型
	 */
	@Select("SELECT CAST(b.code AS CHAR) FROM xbdun_power_user_menu a ,xbdun_power_role_depart b WHERE a.orgCode = b.orgCode AND a.userCode = #{userCode} AND a.orgCode=#{orgCode} AND a.orleDepartId = b.orleDepartId GROUP BY b.code")
	public List<String> queryOrgUserPower(@Param("userCode")long userCode,@Param("orgCode")long orgCode);

	/**
	 * @Title getHasPlats
	 * @Description 获取机构用户可登陆平台
	 * @param orgCode
	 * @param userCode
	 * @return String 返回值类型
	 */
	@Select("SELECT GROUP_CONCAT(bx.pName) FROM ( SELECT SUBSTR(CAST(b.code AS CHAR),1,3) pName FROM xbdun_power_user_menu a ,xbdun_power_role_depart b WHERE a.orgCode = b.orgCode AND a.userCode = ${userCode} AND a.orgCode=${orgCode} AND a.orleDepartId = b.orleDepartId AND b.code NOT IN (SELECT d.code FROM xbdun_power_user_spec d WHERE d.orgCode = ${orgCode} AND d.userCode = ${userCode} AND d.type=2 AND d.code<=999) UNION SELECT SUBSTR(CAST(c.code AS CHAR),1,3) pName FROM xbdun_power_user_spec c  WHERE c.orgCode = ${orgCode} AND c.userCode = ${userCode} AND c.type=1 AND c.code<=999) bx ")
	public String getHasPlats(@Param("userCode")long userCode, @Param("orgCode")long orgCode);
}
